package userInterface;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;

import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;

import controller.Controller;

import domain.User;
import java.util.ArrayList;
import domain.Movie;
import org.jdesktop.beansbinding.ObjectProperty;
import java.util.List;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import org.jdesktop.swingbinding.JListBinding;

public class HomePanel extends JPanel {
	private JTextField name_textField;
	private JTextField surname_textField;
	private JTextField email_textField;
	private JList table;

	private Controller controller;
	/**
	 * Create the panel.
	 */
	public HomePanel(Controller controller) {
		this.controller = controller;
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 211, 278);
		add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("PROFILE");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(10, 25, 191, 27);
		panel.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Name");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setBounds(10, 63, 191, 27);
		panel.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Surname");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2.setBounds(10, 134, 191, 27);
		panel.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("E-mail");
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_3.setBounds(10, 198, 191, 27);
		panel.add(lblNewLabel_3);
		
		name_textField = new JTextField();
		name_textField.setEditable(false);
		name_textField.setBounds(10, 101, 191, 27);
		panel.add(name_textField);
		name_textField.setColumns(10);
		
		surname_textField = new JTextField();
		surname_textField.setEditable(false);
		surname_textField.setBounds(10, 167, 191, 27);
		panel.add(surname_textField);
		surname_textField.setColumns(10);
		
		email_textField = new JTextField();
		email_textField.setEditable(false);
		email_textField.setBounds(10, 224, 191, 27);
		panel.add(email_textField);
		email_textField.setColumns(10);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(231, 11, 482, 278);
		add(panel_1);
		
		JScrollPane scrollPane = new JScrollPane();
		panel_1.add(scrollPane);
		
		table = new JList();
		scrollPane.add(table);
		scrollPane.setViewportView(table);
		initDataBindings();

	}
	
	public void setController(Controller controller) {
		this.controller = controller;
	}
	protected void initDataBindings() {
		BeanProperty<Controller, String> controllerBeanProperty = BeanProperty.create("user.name");
		BeanProperty<JTextField, String> jTextFieldBeanProperty = BeanProperty.create("text");
		AutoBinding<Controller, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ, controller, controllerBeanProperty, name_textField, jTextFieldBeanProperty);
		autoBinding.bind();
		//
		BeanProperty<Controller, String> controllerBeanProperty_1 = BeanProperty.create("user.surname");
		BeanProperty<JTextField, String> jTextFieldBeanProperty_1 = BeanProperty.create("text");
		AutoBinding<Controller, String, JTextField, String> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ, controller, controllerBeanProperty_1, surname_textField, jTextFieldBeanProperty_1);
		autoBinding_1.bind();
		//
		BeanProperty<Controller, String> controllerBeanProperty_2 = BeanProperty.create("user.email");
		BeanProperty<JTextField, String> jTextFieldBeanProperty_2 = BeanProperty.create("text");
		AutoBinding<Controller, String, JTextField, String> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ, controller, controllerBeanProperty_2, email_textField, jTextFieldBeanProperty_2);
		autoBinding_2.bind();
		//
		BeanProperty<Controller, List<String>> controllerBeanProperty_3 = BeanProperty.create("ratedMovies");
		JListBinding<String, Controller, JList> jListBinding = SwingBindings.createJListBinding(UpdateStrategy.READ, controller, controllerBeanProperty_3, table);
		jListBinding.bind();
	}
}
